# -*- coding: UTF-8 -*-
import numpy as np
from os import listdir
from sklearn.svm import SVC
import load_mnist
import time

if __name__ == '__main__':
    path = r'E:\python\python代码\dataSet'

    train_num = 6000  # 训练集数量     上限为6W
    test_num = 600 # 测试集数量     上限为1W

    # read dataSet
    train_dataSet, train_hwLabels  = load_mnist.load_mnist_train(path)
    dataSet, hwLabels = load_mnist.load_mnist_test(path)

    T1 = time.time()
    clf = SVC(C=6, kernel='rbf')
    clf.fit(train_dataSet[:train_num], train_hwLabels[:train_num])

    # 错误检测计数
    errorCount = 0.0

    classifierResult = clf.predict(dataSet[:test_num])

    error_num = np.sum(classifierResult != hwLabels[:test_num])  # 统计分类错误的数目
    T2 = time.time()
    print("测试集数量：", test_num, " 错误次数：", error_num, "  错误率：", error_num / float(test_num))
    print("总共用时：", T2 - T1)


